package com.byd.dms.sf_json.controller;


import com.byd.dms.sf_json.service.JsonDemoService;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;


@Controller
@RequestMapping("/testDemoAction")
public class TestDemoAction {
    
    @Autowired
    private JsonDemoService jsonDemoService;
    
    /**
     * /testDemoAction/peopleDate?roleCount=3&peopleCount=5&markCount=2
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "peopleDate")
    @ResponseBody
    public JSONObject peopleDate(HttpServletRequest request) {
        JSONObject returnJson = new JSONObject();
        Integer roleCount = Integer.parseInt(request.getParameter("roleCount"));
        Integer peopleCount = Integer.parseInt(request.getParameter("peopleCount"));
        Integer markCount = Integer.parseInt(request.getParameter("markCount"));
        try {
            long start = System.currentTimeMillis();
            JSONObject resultDate = jsonDemoService.jsonSort(roleCount, peopleCount, markCount);
            long end = System.currentTimeMillis();
            //            System.out.println("运行时间："+ (end-start));
            returnJson.put("data", resultDate);
            returnJson.put("session", true);
            returnJson.put("msg", "请求数据接口成功");
            returnJson.put("运行时间：", (end - start));
        } catch (Exception e) {
            e.printStackTrace();
            returnJson.put("data", null);
            returnJson.put("session", false);
            returnJson.put("msg", "请求数据接口失败");
        }
        return returnJson;
    }
}